package com.qishenyuan.competition.vo;

import com.qishenyuan.competition.model.Competition;
import com.qishenyuan.competition.utils.DateUtil;
import lombok.Data;

import javax.annotation.Resource;

/**
 * @author Jacky
 * @since 2025-03-05
 */
@Data
public class CompetitionBriefResp {
    private Integer id;

    private String icon;

    private String title;

    private Integer tag;

    private String publisher;

    private String registrationPeriod;

    private String status;

    public static CompetitionBriefResp buildVo(Competition competition){
        CompetitionBriefResp resp = new CompetitionBriefResp();
        resp.setId(competition.getId());
        resp.setIcon(competition.getIcon());
        resp.setTitle(competition.getTitle());
        resp.setTag(competition.getTag());
        resp.setPublisher(competition.getPublisher());
        resp.setRegistrationPeriod(
                DateUtil.format(competition.getRegistrationPeriodBegin(),DateUtil.FORMAT_YYYY_MM_DD)+
                "——"+
                DateUtil.format(competition.getRegistrationPeriodEnd(),DateUtil.FORMAT_YYYY_MM_DD));
        long currentTime = System.currentTimeMillis();
        if(currentTime < competition.getRegistrationPeriodBegin()) {
            resp.setStatus("未开始");
        } else if (currentTime <= competition.getRegistrationPeriodEnd()) {
            resp.setStatus("报名中");
        } else if (currentTime < competition.getGameBeginTime()) {
            resp.setStatus("报名已结束 ");
        } else if (currentTime < competition.getGameEndTime()) {
            resp.setStatus("比赛中");
        } else {
            resp.setStatus("已结束");
        }
        return resp;
    }
}
